// Fill out your copyright notice in the Description page of Project Settings.


#include "STreeItem_File.h"
#include "SlateOptMacros.h"
#include "Widgets/Layout/SScaleBox.h"

BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION

void STreeItem_File::Construct(const FArguments& InArgs)
{

	mScriptPath = InArgs._scriptPath;
	
	SetWidthOverride(InArgs._widthOverride);
	SetHeightOverride(InArgs._heightOverride);
	
	ChildSlot
	.HAlign(HAlign_Fill)
	.VAlign(VAlign_Fill)
	.Padding(0.f)
	[
		SNew(SVerticalBox)
			// Top Border
			+SVerticalBox::Slot()
			.FillHeight(0.1f * InArgs._fillRatioTopBottom)
			.HAlign(HAlign_Fill)
			.VAlign(VAlign_Fill)
			.Padding(0.f)
			[
				SNew(SBorder)
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Fill)
				.BorderImage(new FSlateColorBrush{FLinearColor{0.007499f, 0.007499f, 0.007499f, 1.f}})
			]
			
			// Horizontal Box
			+SVerticalBox::Slot()
			.FillHeight(1.f)
			.HAlign(HAlign_Fill)
			.VAlign(VAlign_Fill)
			[
				SNew(SHorizontalBox)
				// Left Border
				+SHorizontalBox::Slot()
				.FillWidth(0.02f * InArgs._fillRatioLeftRight)
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Fill)
				.Padding(0.f)
				[
					SNew(SBorder)
					.BorderImage(new FSlateColorBrush{FLinearColor{0.007499f, 0.007499f, 0.007499f, 1.f}})
				]
				
				// Button
				+SHorizontalBox::Slot()
				.FillWidth(1.f)
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Fill)
				.Padding(0.f)
				[
					SNew(SButton)
					.HAlign(HAlign_Fill)
					.VAlign(VAlign_Fill)
					.OnClicked(FOnClicked::CreateLambda(
						[this]()
						{
							GEngine->Exec(NULL, *FString::Printf(TEXT("py \"%s\""), *(mScriptPath)));
							return FReply::Handled();
						}))
					[
						SNew(SScaleBox)
						.HAlign(HAlign_Fill)
						.VAlign(VAlign_Fill)
						.Stretch(EStretch::ScaleToFit)
						[
							SNew(STextBlock)
							.Text(FText::FromString(InArgs._buttonText))
							.Justification(ETextJustify::Type::Center)
						]
					]
				]
				
				// Right Border
				+SHorizontalBox::Slot()
				.FillWidth(0.02f * InArgs._fillRatioLeftRight)
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Fill)
				.Padding(0.f)
				[
					SNew(SBorder)
					.BorderImage(new FSlateColorBrush{FLinearColor{0.007499f, 0.007499f, 0.007499f, 1.f}})
				]
			]
			
			// Bottom Border
			+SVerticalBox::Slot()
			.FillHeight(0.1f * InArgs._fillRatioTopBottom)
			.HAlign(HAlign_Fill)
			.VAlign(VAlign_Fill)
			.Padding(0.f)
			[
				SNew(SBorder)
				.HAlign(HAlign_Fill)
				.VAlign(VAlign_Fill)
				.BorderImage(new FSlateColorBrush{FLinearColor{0.007499f, 0.007499f, 0.007499f, 1.f}})
			]
	];

}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
